import request from '@/common/request.js';
import md5 from "../../common/md5.min.js";

export function login(data, success, fail, complete) {
	clearToken();
	let tokenUrl = '/api/blade-auth/oauth/token?tenantId=000000&username=' + data.Phone +
		'&password=' + md5.hex_md5(data.Password) + '&grant_type=password&scope=all&type=account';
	return request({
		url: tokenUrl,
		method: 'post',
		success,
		fail,
		complete
	})
}
export function logout(success, fail, complete) {
	return request({
		url: '/api/blade-auth/oauth/logout',
		method: 'get',
		success,
		fail,
		complete
	});
	clearToken();
}

export function clearToken() {
	uni.removeStorageSync("slToken");
	uni.removeStorageSync("rsToken");
	uni.removeStorageSync("slUserInfo");
}

export function currentUserInfo() {
	const userInfoJson = uni.getStorageSync("slUserInfo");
	if (!userInfoJson) {
		return {};
	}
	const userInfo = JSON.parse(userInfoJson);
	return userInfo;
}
